﻿using Loong.Admin.Localization;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Localization;

namespace Loong.Admin.Permissions;

public class AdminPermissionDefinitionProvider : PermissionDefinitionProvider
{
    private const string QueryDisplayName = "Permission:Query";
    private const string CreateDisplayName = "Permission:Create";
    private const string UpdateDisplayName = "Permission:Update";
    private const string DeleteDisplayName = "Permission:Delete";
    private const string ActivateDisplayName = "Permission:Activate";
    private const string DeactivateDisplayName = "Permission:Deactivate";

    public override void Define(IPermissionDefinitionContext context)
    {
        var myGroup = context.AddGroup(AdminPermissions.GroupName, L("Permission:Admin"));

        var usersPermission = myGroup.AddPermission(AdminPermissions.Users.Default, L("Permission:UserManagement"));
        usersPermission.AddChild(AdminPermissions.Users.Create, L(CreateDisplayName));
        usersPermission.AddChild(AdminPermissions.Users.Update, L(UpdateDisplayName));
        usersPermission.AddChild(AdminPermissions.Users.Delete, L(DeleteDisplayName));

        var rolesPermission = myGroup.AddPermission(AdminPermissions.Roles.Default, L("Permission:RoleManagement"));
        rolesPermission.AddChild(AdminPermissions.Roles.Create, L(CreateDisplayName));
        rolesPermission.AddChild(AdminPermissions.Roles.Update, L(UpdateDisplayName));
        rolesPermission.AddChild(AdminPermissions.Roles.Delete, L(DeleteDisplayName));
    }

    private static LocalizableString L(string name)
    {
        return LocalizableString.Create<AdminResource>(name);
    }
}
